package com.lianniu.web.tea.user.favour.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.user.favour.model.TeaFavour;
import com.lianniu.web.tea.user.favour.service.ITeaUserFavourService;

@Controller
@RequestMapping("/rest/tea/favour")
public class TeaFavourController {

	private final static Logger logger = Logger.getLogger(TeaFavourController.class);
	
	@Autowired
	private ITeaUserFavourService teaUserFavourService;
	
	@RequestMapping(value="/addFavour",method = {RequestMethod.POST,RequestMethod.GET} )
	public @ResponseBody BaseResult addFavour(HttpServletRequest req){
		logger.info("TeaFavourController  addFavour begin.");
		try {
			logger.info("addFavour begin.");
			String markId = req.getParameter("markId");
			String userId = req.getParameter("userId");
			TeaFavour teaFavour = new TeaFavour();
			teaFavour.setMarkid(markId);
			teaFavour.setUserid(Long.valueOf(userId));
			BaseResult baseResult = teaUserFavourService.addFavour(teaFavour);
			logger.info("addFavour end.");
			logger.info("TeaFavourController addFavour end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaFavourController addFavour error:" + e.getMessage());
			logger.error("TeaFavourController addFavour end.");
			return BaseResult.exception(e.getMessage());
		}
	}
	
	@RequestMapping(value="/deleteFavour",method = {RequestMethod.POST,RequestMethod.GET} )
	public @ResponseBody BaseResult deleteFavour(HttpServletRequest req){
		logger.info("TeaFavourController deleteFavour begin.");
		try {
			logger.info("deleteFavour begin.");
			String id = req.getParameter("id");
			BaseResult baseResult = teaUserFavourService.deleteFavour(id);
			logger.info("deleteFavour end.");
			logger.info("TeaFavourController deleteFavour end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaFavourController deleteFavour error:" + e.getMessage());
			logger.error("TeaFavourController deleteFavour end.");
			return BaseResult.exception(e.getMessage());
		}
	}
	
	@RequestMapping(value="/checkFavour",method = {RequestMethod.POST,RequestMethod.GET} )
	public @ResponseBody BaseResult checkFavour(HttpServletRequest req){
		logger.info("TeaFavourController checkFavour begin.");
		try {
			logger.info("checkFavour begin.");
			String productId = req.getParameter("productId");
			String userId = req.getParameter("userId");
			BaseResult baseResult = teaUserFavourService.checkFavour(productId,userId);
			logger.info("checkFavour end.");
			logger.info("TeaFavourController checkFavour end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaFavourController checkFavour error:" + e.getMessage());
			logger.error("TeaFavourController checkFavour end.");
			return BaseResult.exception(e.getMessage());
		}
	}

}
